package cn.stacey.day11;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.junit.Test;

public class DemoReader {
	@Test
	public void test() {
//		String path="‪D:\\视频\\day11\\倚天屠龙记utf-8.txt";
		String path="D:\\视频\\day11\\倚天屠龙记utf-8.txt";
		System.out.println(new File(path).exists());
		//字符流，需要在构造器里面指定字节流
		try(InputStreamReader ir=new InputStreamReader(new FileInputStream(path),"utf-8");){
			char[] chars=new char[1024];
			int count=0;
			while((count=ir.read(chars))!=-1) {
				System.out.println(new String(chars,0,count));
			}
			
			
		}catch(IOException e) {
			e.printStackTrace();
		}
		
	}
	@Test
	public void test1() {
		String path="D:\\视频\\day11\\倚天屠龙记utf-8.txt";
//		System.out.println(new File(path).exists());
		try(FileReader fr=new FileReader(path);
				){
			char[] chars=new char[1024];
			int count=0;
			while((count=fr.read(chars))!=-1) {
				System.out.println(new String(chars,0,count));
			}
			
		}catch(IOException e) {
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void test2() {
		String path="D:\\视频\\day11\\倚天屠龙记utf-8.txt";
		try(BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(path),"utf-8"));){
			String line;
			while((line=br.readLine())!=null) {
				System.out.println(line);
			}
			
			//System.out.println();
			
		}catch(IOException e) {
			e.printStackTrace();
		}
		
	}
}
